package com.example.jsruntimedemo.js.view;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;

import com.example.jsruntimedemo.js.JsApplication;
import com.example.jsruntimedemo.js.JsContext;
import com.example.jsruntimedemo.js.dom.DomButton;
import com.example.jsruntimedemo.js.dom.DomText;

public class ButtonJsView extends JsView<Button, DomButton> {
    @Override
    public String getType() {
        return "text";
    }

    @Override
    public Button createViewInternal(Context context) {
        Button button = new Button(context);
        button.setGravity(Gravity.CENTER);
        button.setText(mDomElement.text);
        button.setTextSize(mDomElement.textSize);
        button.setTextColor(Color.parseColor(mDomElement.textColor));

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mDomElement.onClick != null) {
                    mDomElement.onClick.call(mDomElement.onClick.getRuntime(), null);
                }
            }
        });
        return button;
    }
}
